package b.b.h;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.ListAdapter;
import android.widget.ListView;
import b.i.l.c;
import java.lang.reflect.Field;

/* compiled from: DropDownListView */
public class p extends ListView {
    public final Rect a = new Rect();
    public int b = 0;
    public int c = 0;
    public int d = 0;
    public int e = 0;
    public int f;
    public Field g;
    public a h;
    public boolean i;
    public boolean j;
    public boolean k;
    public c l;
    public b m;

    /* compiled from: DropDownListView */
    public class b implements Runnable {
        public void run() {
            p pVar = p.this;
            pVar.m = null;
            pVar.drawableStateChanged();
        }
    }

    /* compiled from: DropDownListView */
    public static class a extends b.b.e.a.c {
        public boolean b = true;

        public a(Drawable drawable) {
            super(drawable);
        }

        public void draw(Canvas canvas) {
            if (this.b) {
                this.a.draw(canvas);
            }
        }

        public void setHotspot(float f, float f2) {
            if (this.b) {
                this.a.setHotspot(f, f2);
            }
        }

        public void setHotspotBounds(int i, int i2, int i3, int i4) {
            if (this.b) {
                this.a.setHotspotBounds(i, i2, i3, i4);
            }
        }

        public boolean setState(int[] iArr) {
            return this.b ? this.a.setState(iArr) : false;
        }

        public boolean setVisible(boolean z, boolean z2) {
            return this.b ? super.setVisible(z, z2) : false;
        }
    }

    public p(Context context, boolean z) {
        super(context, null, 2130968878);
        this.j = z;
        setCacheColorHint(0);
        try {
            Field declaredField = AbsListView.class.getDeclaredField("mIsChildViewEnabled");
            this.g = declaredField;
            declaredField.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    private void setSelectorEnabled(boolean z) {
        a aVar = this.h;
        if (aVar != null) {
            aVar.b = z;
        }
    }

    public int a(int i, int i2, int i3) {
        int listPaddingTop = getListPaddingTop();
        int listPaddingBottom = getListPaddingBottom();
        int dividerHeight = getDividerHeight();
        Drawable divider = getDivider();
        ListAdapter adapter = getAdapter();
        if (adapter == null) {
            return listPaddingTop + listPaddingBottom;
        }
        listPaddingTop += listPaddingBottom;
        if (dividerHeight <= 0 || divider == null) {
            dividerHeight = 0;
        }
        int count = adapter.getCount();
        View view = null;
        int i4 = 0;
        int i5 = 0;
        int i6 = 0;
        while (i4 < count) {
            int itemViewType = adapter.getItemViewType(i4);
            if (itemViewType != i5) {
                view = null;
                i5 = itemViewType;
            }
            view = adapter.getView(i4, view, this);
            LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams == null) {
                layoutParams = generateDefaultLayoutParams();
                view.setLayoutParams(layoutParams);
            }
            itemViewType = layoutParams.height;
            if (itemViewType > 0) {
                itemViewType = MeasureSpec.makeMeasureSpec(itemViewType, 1073741824);
            } else {
                itemViewType = MeasureSpec.makeMeasureSpec(0, 0);
            }
            view.measure(i, itemViewType);
            view.forceLayout();
            if (i4 > 0) {
                listPaddingTop += dividerHeight;
            }
            listPaddingTop += view.getMeasuredHeight();
            if (listPaddingTop >= i2) {
                if (i3 >= 0 && i4 > i3 && i6 > 0 && listPaddingTop != i2) {
                    i2 = i6;
                }
                return i2;
            }
            if (i3 >= 0 && i4 >= i3) {
                i6 = listPaddingTop;
            }
            i4++;
        }
        return listPaddingTop;
    }

    /* JADX WARNING: Removed duplicated region for block: B:66:0x013c  */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x0157  */
    /* JADX WARNING: Removed duplicated region for block: B:68:0x0141  */
    /* JADX WARNING: Missing block: B:5:0x0010, code skipped:
            if (r3 != 3) goto L_0x0121;
     */
    public boolean b(android.view.MotionEvent r17, int r18) {
        /*
        r16 = this;
        r1 = r16;
        r2 = r17;
        r3 = r17.getActionMasked();
        r4 = 0;
        r5 = 1;
        if (r3 == r5) goto L_0x0016;
    L_0x000c:
        r0 = 2;
        if (r3 == r0) goto L_0x0014;
    L_0x000f:
        r0 = 3;
        if (r3 == r0) goto L_0x001d;
    L_0x0012:
        goto L_0x0121;
    L_0x0014:
        r0 = 1;
        goto L_0x0017;
    L_0x0016:
        r0 = 0;
    L_0x0017:
        r6 = r17.findPointerIndex(r18);
        if (r6 >= 0) goto L_0x0020;
    L_0x001d:
        r0 = 0;
        goto L_0x0122;
    L_0x0020:
        r7 = r2.getX(r6);
        r7 = (int) r7;
        r6 = r2.getY(r6);
        r6 = (int) r6;
        r8 = r1.pointToPosition(r7, r6);
        r9 = -1;
        if (r8 != r9) goto L_0x0033;
    L_0x0031:
        goto L_0x0123;
    L_0x0033:
        r0 = r16.getFirstVisiblePosition();
        r0 = r8 - r0;
        r10 = r1.getChildAt(r0);
        r7 = (float) r7;
        r6 = (float) r6;
        r1.k = r5;
        r1.drawableHotspotChanged(r7, r6);
        r0 = r16.isPressed();
        if (r0 != 0) goto L_0x004d;
    L_0x004a:
        r1.setPressed(r5);
    L_0x004d:
        r16.layoutChildren();
        r0 = r1.f;
        if (r0 == r9) goto L_0x006a;
    L_0x0054:
        r11 = r16.getFirstVisiblePosition();
        r0 = r0 - r11;
        r0 = r1.getChildAt(r0);
        if (r0 == 0) goto L_0x006a;
    L_0x005f:
        if (r0 == r10) goto L_0x006a;
    L_0x0061:
        r11 = r0.isPressed();
        if (r11 == 0) goto L_0x006a;
    L_0x0067:
        r0.setPressed(r4);
    L_0x006a:
        r1.f = r8;
        r0 = r10.getLeft();
        r0 = (float) r0;
        r0 = r7 - r0;
        r11 = r10.getTop();
        r11 = (float) r11;
        r11 = r6 - r11;
        r10.drawableHotspotChanged(r0, r11);
        r0 = r10.isPressed();
        if (r0 != 0) goto L_0x0086;
    L_0x0083:
        r10.setPressed(r5);
    L_0x0086:
        r11 = r16.getSelector();
        if (r11 == 0) goto L_0x0090;
    L_0x008c:
        if (r8 == r9) goto L_0x0090;
    L_0x008e:
        r12 = 1;
        goto L_0x0091;
    L_0x0090:
        r12 = 0;
    L_0x0091:
        if (r12 == 0) goto L_0x0096;
    L_0x0093:
        r11.setVisible(r4, r4);
    L_0x0096:
        r0 = r1.a;
        r13 = r10.getLeft();
        r14 = r10.getTop();
        r15 = r10.getRight();
        r5 = r10.getBottom();
        r0.set(r13, r14, r15, r5);
        r5 = r0.left;
        r13 = r1.b;
        r5 = r5 - r13;
        r0.left = r5;
        r5 = r0.top;
        r13 = r1.c;
        r5 = r5 - r13;
        r0.top = r5;
        r5 = r0.right;
        r13 = r1.d;
        r5 = r5 + r13;
        r0.right = r5;
        r5 = r0.bottom;
        r13 = r1.e;
        r5 = r5 + r13;
        r0.bottom = r5;
        r0 = r1.g;	 Catch:{ IllegalAccessException -> 0x00e7 }
        r0 = r0.getBoolean(r1);	 Catch:{ IllegalAccessException -> 0x00e7 }
        r5 = r10.isEnabled();	 Catch:{ IllegalAccessException -> 0x00e7 }
        if (r5 == r0) goto L_0x00eb;
    L_0x00d3:
        r5 = r1.g;	 Catch:{ IllegalAccessException -> 0x00e7 }
        if (r0 != 0) goto L_0x00d9;
    L_0x00d7:
        r0 = 1;
        goto L_0x00da;
    L_0x00d9:
        r0 = 0;
    L_0x00da:
        r0 = java.lang.Boolean.valueOf(r0);	 Catch:{ IllegalAccessException -> 0x00e7 }
        r5.set(r1, r0);	 Catch:{ IllegalAccessException -> 0x00e7 }
        if (r8 == r9) goto L_0x00eb;
    L_0x00e3:
        r16.refreshDrawableState();	 Catch:{ IllegalAccessException -> 0x00e7 }
        goto L_0x00eb;
    L_0x00e7:
        r0 = move-exception;
        r0.printStackTrace();
    L_0x00eb:
        if (r12 == 0) goto L_0x0106;
    L_0x00ed:
        r0 = r1.a;
        r5 = r0.exactCenterX();
        r0 = r0.exactCenterY();
        r12 = r16.getVisibility();
        if (r12 != 0) goto L_0x00ff;
    L_0x00fd:
        r12 = 1;
        goto L_0x0100;
    L_0x00ff:
        r12 = 0;
    L_0x0100:
        r11.setVisible(r12, r4);
        r11.setHotspot(r5, r0);
    L_0x0106:
        r0 = r16.getSelector();
        if (r0 == 0) goto L_0x0111;
    L_0x010c:
        if (r8 == r9) goto L_0x0111;
    L_0x010e:
        r0.setHotspot(r7, r6);
    L_0x0111:
        r1.setSelectorEnabled(r4);
        r16.refreshDrawableState();
        r5 = 1;
        if (r3 != r5) goto L_0x0121;
    L_0x011a:
        r5 = r1.getItemIdAtPosition(r8);
        r1.performItemClick(r10, r8, r5);
    L_0x0121:
        r0 = 1;
    L_0x0122:
        r5 = 0;
    L_0x0123:
        if (r0 == 0) goto L_0x0127;
    L_0x0125:
        if (r5 == 0) goto L_0x013f;
    L_0x0127:
        r1.k = r4;
        r1.setPressed(r4);
        r16.drawableStateChanged();
        r3 = r1.f;
        r5 = r16.getFirstVisiblePosition();
        r3 = r3 - r5;
        r3 = r1.getChildAt(r3);
        if (r3 == 0) goto L_0x013f;
    L_0x013c:
        r3.setPressed(r4);
    L_0x013f:
        if (r0 == 0) goto L_0x0157;
    L_0x0141:
        r3 = r1.l;
        if (r3 != 0) goto L_0x014c;
    L_0x0145:
        r3 = new b.i.l.c;
        r3.m5077init(r1);
        r1.l = r3;
    L_0x014c:
        r3 = r1.l;
        r4 = r3.p;
        r5 = 1;
        r3.p = r5;
        r3.onTouch(r1, r2);
        goto L_0x0164;
    L_0x0157:
        r2 = r1.l;
        if (r2 == 0) goto L_0x0164;
    L_0x015b:
        r3 = r2.p;
        if (r3 == 0) goto L_0x0162;
    L_0x015f:
        r2.d();
    L_0x0162:
        r2.p = r4;
    L_0x0164:
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.b.h.p.b(android.view.MotionEvent, int):boolean");
    }

    public final void c() {
        Drawable selector = getSelector();
        if (selector != null && this.k && isPressed()) {
            selector.setState(getDrawableState());
        }
    }

    public void dispatchDraw(Canvas canvas) {
        if (!this.a.isEmpty()) {
            Drawable selector = getSelector();
            if (selector != null) {
                selector.setBounds(this.a);
                selector.draw(canvas);
            }
        }
        super.dispatchDraw(canvas);
    }

    public void drawableStateChanged() {
        if (this.m == null) {
            super.drawableStateChanged();
            setSelectorEnabled(true);
            c();
        }
    }

    public boolean hasFocus() {
        return this.j || super.hasFocus();
    }

    public boolean hasWindowFocus() {
        return this.j || super.hasWindowFocus();
    }

    public boolean isFocused() {
        return this.j || super.isFocused();
    }

    public boolean isInTouchMode() {
        return (this.j && this.i) || super.isInTouchMode();
    }

    public void onDetachedFromWindow() {
        this.m = null;
        super.onDetachedFromWindow();
    }

    public boolean onHoverEvent(MotionEvent motionEvent) {
        if (VERSION.SDK_INT < 26) {
            return super.onHoverEvent(motionEvent);
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 10 && this.m == null) {
            b bVar = new b();
            this.m = bVar;
            post(bVar);
        }
        boolean onHoverEvent = super.onHoverEvent(motionEvent);
        if (actionMasked == 9 || actionMasked == 7) {
            int pointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
            if (!(pointToPosition == -1 || pointToPosition == getSelectedItemPosition())) {
                View childAt = getChildAt(pointToPosition - getFirstVisiblePosition());
                if (childAt.isEnabled()) {
                    setSelectionFromTop(pointToPosition, childAt.getTop() - getTop());
                }
                c();
            }
        } else {
            setSelection(-1);
        }
        return onHoverEvent;
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            this.f = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
        }
        b bVar = this.m;
        if (bVar != null) {
            p pVar = p.this;
            pVar.m = null;
            pVar.removeCallbacks(bVar);
        }
        return super.onTouchEvent(motionEvent);
    }

    public void setListSelectionHidden(boolean z) {
        this.i = z;
    }

    public void setSelector(Drawable drawable) {
        a aVar = drawable != null ? new a(drawable) : null;
        this.h = aVar;
        super.setSelector(aVar);
        Rect rect = new Rect();
        if (drawable != null) {
            drawable.getPadding(rect);
        }
        this.b = rect.left;
        this.c = rect.top;
        this.d = rect.right;
        this.e = rect.bottom;
    }
}
